#include "LineDisplayImp.h"

using namespace Utility::LoggerLib;
CLineDisplay::CLineDisplay()
{
	m_portInfo.nParity = 2;
	m_portInfo.hCom = NULL;
	m_portInfo.oRead.hEvent = NULL;
	m_portInfo.oWrite.hEvent = NULL;
	m_nError = 0;
}

CLineDisplay::~CLineDisplay()
{
	if (NULL != m_portInfo.hCom)
	{
		Close(); //Zhwang to do:
	}
}

int CLineDisplay::Open()
{
	Log(DEBUG_LEVEL, ELineDisplay, _T("Open the line display, port is COM%d."), m_portInfo.nPort);
	m_portInfo.hCom = PR_OpenCom(m_portInfo.nPort, m_portInfo.oWrite, m_portInfo.oRead, m_portInfo.nParity, m_nError);
	
	if (m_nError != 0)
	{
		Log(ERROR_LEVEL, ELineDisplay, L"Fail to initialize line display, the error code is %d.", m_nError);
	}

	return m_nError;
}

int CLineDisplay::Close()
{
	Log(DEBUG_LEVEL,ELineDisplay, _T("Close the line display, port is COM%d."), m_portInfo.nPort);
	if(PR_CloseCom(m_portInfo.hCom, m_portInfo.oWrite, m_portInfo.oRead))
	{
		m_portInfo.hCom = NULL;
		return 0;
	}

	return 1;
}



/*

BOOL CLineDisplay::Display(LPCTSTR pStr, int nLength, int nLine)
{
    if (1 == nLine)
    {
        SendString(_T("\x10\x00"),2);
    }
    else
    {
        SendString(_T("\x10\x14"),2);
    }

    return SendString(pStr, nLength);
}

BOOL CLineDisplay::SendString(LPCTSTR lpStr, int nLen)
{
    return PR_SendStr2Com(m_hCom, lpStr, nLen, m_oWrite);
}

*/

////////////////////////////////////////////////////////////////////////////
//// VC220
/*
CVC220::CVC220(int nPort)
: CLineDisplay(VC220, nPort)
{

}

BOOL CVC220::Initialize()
{
    CLineDisplay::Initialize();
    return SendString(_T("\x1f"),1);
}
*/